//初始化加载页面的时候设置tab项设置为'测试曲线'
window.localStorage.nowtab="dp3";
//1.根据url初始化背景色
function initBackground(pageName) {
    if (window.localStorage.nowtab == "dp1") {//历史数据
        $("#hg_nav_li1").css({"background": "#ffffff", "color": "#083156", "font-weight": "bold"});
        $("#dp1").css({"color": "#083156"});
        $("#hg_nav_li2").css({"background": "#083156", "color": "#ffffff", "font-weight": "normal"});
        $("#dp2").css({"color": "#ffffff"});
        $("#hg_nav_li3").css({"background": "#083156", "color": "#ffffff", "font-weight": "normal"});
        $("#dp3").css({"color": "#ffffff"});
        $("#hg_nav_li4").css({"background": "#083156", "color": "#ffffff", "font-weight": "normal"});
        $("#dp4").css({"color": "#ffffff"});
    } else if (window.localStorage.nowtab == "dp2") {//数据列表
        $("#hg_nav_li1").css({"background": "#083156", "color": "#ffffff", "font-weight": "normal"});
        $("#dp1").css({"color": "#ffffff"});
        $("#hg_nav_li2").css({"background": "#ffffff", "color": "#083156", "font-weight": "bold"});
        $("#dp2").css({"color": "#083156"});
        $("#hg_nav_li3").css({"background": "#083156", "color": "#ffffff", "font-weight": "normal"});
        $("#dp3").css({"color": "#ffffff"});
        $("#hg_nav_li4").css({"background": "#083156", "color": "#ffffff", "font-weight": "normal"});
        $("#dp4").css({"color": "#ffffff"});
    } else if (window.localStorage.nowtab == "dp3") {//测试曲线
        $("#hg_nav_li1").css({"background": "#083156", "color": "#ffffff", "font-weight": "normal"});
        $("#dp1").css({"color": "#ffffff"});
        $("#hg_nav_li2").css({"background": "#083156", "color": "#ffffff", "font-weight": "normal"});
        $("#dp2").css({"color": "#ffffff"});
        $("#hg_nav_li3").css({"background": "#ffffff", "color": "#083156", "font-weight": "bold"});
        $("#dp3").css({"color": "#083156"});
        $("#hg_nav_li4").css({"background": "#083156", "color": "#ffffff", "font-weight": "normal"});
        $("#dp4").css({"color": "#ffffff"});
    }else if (window.localStorage.nowtab == "dp4") {//报警信息
        $("#hg_nav_li1").css({"background": "#083156", "color": "#ffffff", "font-weight": "normal"});
        $("#dp1").css({"color": "#ffffff"});
        $("#hg_nav_li2").css({"background": "#083156", "color": "#ffffff", "font-weight": "normal"});
        $("#dp2").css({"color": "#ffffff"});
        $("#hg_nav_li3").css({"background": "#083156", "color": "#ffffff", "font-weight": "normal"});
        $("#dp3").css({"color": "#ffffff"});
        $("#hg_nav_li4").css({"background": "#ffffff", "color": "#083156", "font-weight": "bold"});
        $("#dp4").css({"color": "#083156"});
    }
}
//2.通过jquery修改a标签的href属性
function dp1Click(){//历史数据
    window.localStorage.nowtab="dp1";
    let labcode= $.cookie('labcode');
    let nowprimarykey= $.cookie('nowprimarykey');
    //隐藏父窗体-iframeBottom
    $("#iframeBottom",parent.document).css('display','none');
    $("#dp1").attr("href",top.basePath+"page/HistoryData?labcode="+labcode+"&primarykey="+nowprimarykey);
}
function dp2Click(){//数据列表
    window.localStorage.nowtab="dp2";
    let labcode= $.cookie('labcode');
    let nowprimarykey= $.cookie('nowprimarykey');
    //隐藏父窗体-iframeBottom
    $("#iframeBottom",parent.document).css('display','none');
   /* $("#dp2").attr("href",top.basePath+"page/DataList?labcode="+labcode+"&primarykey="+nowprimarykey);*/
    $("#dp2").attr("href","../dataList/dataList.html");
}
function dp3Click(){//测试曲线
    window.localStorage.nowtab="dp3";
    let labcode= $.cookie('labcode');
    //let nowtestunitno= $.cookie('nowtestunitno');
    let nowprimarykey= $.cookie('nowprimarykey');
    //top.document.location.href=basePath+"page/CurveDisplay?labcode="+labcode+"&testdate="+nowprimarykey;
    $("#dp3").attr("href",top.basePath+"page/CurveDisplayContent?labcode="+labcode+"&testdate="+nowprimarykey);
    //$("#dp3").attr("top.document.location.href",top.basePath+"page/CurveDisplayContent?labcode="+labcode+"&testdate="+nowprimarykey);
}
function dp4Click(){//报警信息
    window.localStorage.nowtab="dp4";
    let labcode= $.cookie('labcode');
    //let nowtestunitno= $.cookie('nowtestunitno');
    let nowprimarykey= $.cookie('nowprimarykey');
    //top.document.location.href=basePath+"page/CurveDisplay?labcode="+labcode+"&testdate="+nowprimarykey;
    $("#dp4").attr("href","../yyi/alarmList.html");
    //$("#dp3").attr("top.document.location.href",top.basePath+"page/CurveDisplayContent?labcode="+labcode+"&testdate="+nowprimarykey);
}

$(document).ready(function () {
    //访问父页面的CommonUtils.js
    var pageName = parent.getCurrentPageUrl();
    //根据url初始化背景色
    initBackground(pageName);
    $("#hg_nav_li1").mouseover(function () {
        $("#hg_nav_li1").css({"background": "#ffffff", "color": "#083156", "font-weight": "bold"});
        $("#hg_nav_li2").css({"background": "#083156", "color": "#ffffff", "font-weight": "normal"});
        $("#hg_nav_li3").css({"background": "#083156", "color": "#ffffff", "font-weight": "normal"});
        $("#hg_nav_li4").css({"background": "#083156", "color": "#ffffff", "font-weight": "normal"});
        $("#dp1").css({"color": "#083156"});
        $("#dp2").css({"color": "#ffffff"});
        $("#dp3").css({"color": "#ffffff"});
        $("#dp4").css({"color": "#ffffff"});
    });
    $("#hg_nav_li1").mouseout(function () {
        initBackground(pageName);
    });
    $("#hg_nav_li2").mouseover(function () {
        $("#hg_nav_li1").css({"background": "#083156", "color": "#ffffff", "font-weight": "normal"});
        $("#hg_nav_li2").css({"background": "#ffffff", "color": "#083156", "font-weight": "bold"});
        $("#hg_nav_li3").css({"background": "#083156", "color": "#ffffff", "font-weight": "normal"});
        $("#hg_nav_li4").css({"background": "#083156", "color": "#ffffff", "font-weight": "normal"});
        $("#dp1").css({"color": "#ffffff"});
        $("#dp2").css({"color": "#083156"});
        $("#dp3").css({"color": "#ffffff"});
        $("#dp4").css({"color": "#ffffff"});
    });
    $("#hg_nav_li2").mouseout(function () {
        initBackground(pageName);
    });
    $("#hg_nav_li3").mouseover(function () {
        $("#hg_nav_li1").css({"background": "#083156", "color": "#ffffff", "font-weight": "normal"});
        $("#hg_nav_li2").css({"background": "#083156", "color": "#ffffff", "font-weight": "normal"});
        $("#hg_nav_li3").css({"background": "#ffffff", "color": "#083156", "font-weight": "bold"});
        $("#hg_nav_li4").css({"background": "#083156", "color": "#ffffff", "font-weight": "normal"});
        $("#dp1").css({"color": "#ffffff"});
        $("#dp2").css({"color": "#ffffff"});
        $("#dp3").css({"color": "#083156"});
        $("#dp4").css({"color": "#ffffff"});
    });
    $("#hg_nav_li3").mouseout(function () {
        initBackground(pageName);
    });
    $("#hg_nav_li4").mouseover(function () {
        $("#hg_nav_li1").css({"background": "#083156", "color": "#ffffff", "font-weight": "normal"});
        $("#hg_nav_li2").css({"background": "#083156", "color": "#ffffff", "font-weight": "normal"});
        $("#hg_nav_li3").css({"background": "#083156", "color": "#ffffff", "font-weight": "normal"});
        $("#hg_nav_li4").css({"background": "#ffffff", "color": "#083156", "font-weight": "bold"});
        $("#dp1").css({"color": "#ffffff"});
        $("#dp2").css({"color": "#ffffff"});
        $("#dp3").css({"color": "#ffffff"});
        $("#dp4").css({"color": "#083156"});
    });
    $("#hg_nav_li4").mouseout(function () {
        initBackground(pageName);
    });


    //以下是最左侧侧边栏的相关控制
    var trigger = $('.hamburger');
    //控制页面是否变暗
    window.overlay = $('.overlay');
    window.isClosed = false;

    trigger.click(function () {
        hamburger_cross();
    });

    //控制点击按钮的变化
    function hamburger_cross() {

        if (isClosed == true) {
            overlay.hide();
            trigger.removeClass('is-open');
            trigger.addClass('is-closed');
            isClosed = false;
        } else {
            overlay.show();
            trigger.removeClass('is-closed');
            trigger.addClass('is-open');
            isClosed = true;
        }
    }
    //控制侧边栏的显示和隐藏
    $('[data-toggle="offcanvas"]').click(function () {
        $('#wrapper').toggleClass('toggled');
    });
});
